﻿using System;
using System.Collections.Generic;
using System.Linq;
using Complaint.Models.Dtos.Validators;

namespace Complaint.Models.Dtos
{
    public partial class Comment : IEntity
    {
        public Comment()
        {
            DateAdded = DateTime.Now;
            Status = true;
        }

        #region Implementation of IEntity
        public bool IsValid
        {
            get
            {
                return (GetRuleViolations().Count() == 0);
            }
        }

        public IEnumerable<RuleViolation> GetRuleViolations()
        {
            if (String.IsNullOrEmpty(Name))
                yield return new RuleViolation("Name is required", "Name");

            if (!String.IsNullOrEmpty(Email))
                if (!EmailValidator.IsValidEmail(Email))
                    yield return new RuleViolation("Please enter a valid email address", "Email");

            if (String.IsNullOrEmpty(Comment1))
                yield return new RuleViolation("Comment is required", "Comment1");

            if (!String.IsNullOrEmpty(Comment1))
                if (Comment1.Length > 500)
                    yield return new RuleViolation("Max length is 500 characters.", "Comment1");
        }
        #endregion
    }
}
